#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>


 char *const addenvp[]={
            (char *const)"MYVAL=123456789",
            NULL
        };
//char* newnew=(char*)"myVAL=666666";
int main()
{
    printf("我的程序要运行了...\n");
    if(fork()==0)
    {
        printf("I am child, my pid is %d\n", getpid());
        sleep(1);

        char *const argv[]={
            (char *const)"other",
            (char *const)"-a",
            (char *const)"-b",
            NULL
        };

        for(int i = 0;addenvp[i];i++)
        {
            putenv(addenvp[i]);
        }

        extern char** environ;

        execvpe("./other",argv,environ);

        //execvpe("./other",argv,envp);

        //execvp(argv[0],argv);//这里ls也是argv[0]，所以这里我就写了这个

        //execv("/usr/bin/ls",argv);
        //execlp("ls","ls","-al",NULL);


        //child
        //execl("/usr/bin/python3","python","other.py",NULL);
        //printf("I am child, my pid is %d\n", getpid());
        //execl("./other","other",NULL);
        //后面的代码如果执行，那么就是exec失败了
        exit(1);
    }
    waitpid(-1,NULL,0);
    printf("我的程序运行完毕了!\n");
    return 0;
}


int main1()
{
    printf("我的程序要运行了...\n");
    //execl("/usr/bin/ls","ls","-a","-l",NULL);
    int n = execl("usr/bin/ls","ls","-a","-l",NULL);//和之前比，usr前面少了/
    printf("我的程序运行完毕了: %d\n", n);
    exit(1);
}

